home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / pctj0787.arc / MEMCHK.C < prev    next >
C/C++ Source or Header  |  1987-05-27  |  846b  |  36 lines

  1. /*
  2.  *    memchk -- look for random-access memory at
  3.  *    a specified location; return non-zero if found
  4.  */
  5.  
  6. #include <dos.h>
  7. #include <memory.h>
  8.  
  9. int
  10. memchk(seg, os)
  11. unsigned int seg;
  12. unsigned int os;
  13. {
  14.     unsigned char tstval, oldval, newval;
  15.     unsigned int ds;
  16.     struct SREGS segregs;
  17.  
  18.     /* get value of current data segment */
  19.     segread(&segregs);
  20.     ds = segregs.ds;
  21.     /* save current contents of test location */
  22.     movedata(seg, os, ds, (unsigned)&oldval, 1);
  23.     /* copy a known value into test location */
  24.     tstval = 0xFC;
  25.     movedata(ds, (unsigned)&tstval, seg, os, 1);
  26.     /* read test value back and comapre to value written */
  27.     movedata(seg, os, ds, (unsigned)&newval, 1);
  28.     if (newval != tstval)
  29.         return (0);
  30.  
  31.     /* restore original contents of test location */
  32.     movedata(ds, (unsigned)&oldval, seg, os, 1);
  33.  
  34.     return (1);
  35. }
  36.